package safrain.nodelet.pool.reseter;

import safrain.nodelet.pool.Pool;
import safrain.nodelet.structure.FieldInfo;
import safrain.nodelet.template.field.BooleanField;
import safrain.nodelet.template.field.ByteField;
import safrain.nodelet.template.field.CharField;
import safrain.nodelet.template.field.DoubleField;
import safrain.nodelet.template.field.FloatField;
import safrain.nodelet.template.field.IntField;
import safrain.nodelet.template.field.LongField;
import safrain.nodelet.template.field.ReferenceField;
import safrain.nodelet.template.field.ShortField;
import safrain.nodelet.template.field.ValueField;

public class DefaultReseter implements IReseter {
	private ValueField<Pool> valueField;

	// 各种重置默认值
	private int resetIntValue = 0;
	private long resetLongValue = 0L;
	private float resetFloatValue = 0.0f;
	private double resetDoubleValue = 0.0D;
	private short resetShortValue = 0;
	private byte resetByteValue = 0;
	private boolean resetBooleanValue = false;
	private char resetCharValue = 0;
	private Object resetReferenceValue = null;

	@Override
	public void init(FieldInfo fieldInfo) {
		valueField = ValueField.<Pool> getValueField(fieldInfo);
		setResetValue(this.valueField);
	}

	@Override
	public void reset(Object object) {
		valueField.set(object);
	}

	/**
	 * 给Field设置默认值
	 */
	private void setResetValue(ValueField<Pool> baseField) {
		if (baseField instanceof IntField) {
			baseField.setValue(resetIntValue);
		} else if (baseField instanceof LongField) {
			baseField.setValue(resetLongValue);
		} else if (baseField instanceof FloatField) {
			baseField.setValue(resetFloatValue);
		} else if (baseField instanceof DoubleField) {
			baseField.setValue(resetDoubleValue);
		} else if (baseField instanceof ShortField) {
			baseField.setValue(resetShortValue);
		} else if (baseField instanceof ByteField) {
			baseField.setValue(resetByteValue);
		} else if (baseField instanceof BooleanField) {
			baseField.setValue(resetBooleanValue);
		} else if (baseField instanceof CharField) {
			baseField.setValue(resetCharValue);
		} else if (baseField instanceof ReferenceField) {
			baseField.setValue(resetReferenceValue);
		}
	}

}
